<?php

use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Migrations\Migration;

return new class extends Migration {
    
    protected $connection = "default";

    public function up(): void
    {
        \support\Db::schema()->create('admin_rule',function (Blueprint $table){
            $table->increments('id');
            $table->string("v0");
            $table->string("v1");
            $table->string("v2");
            $table->string("v3");
            $table->string("v4");
            $table->string("v5");

            $table->comment("casbin规则表");
        });

        \support\Db::schema()->create('admin_role',function (Blueprint $table){
            $table->increments('id');

            $table->string("name")->nullable()->comment("角色名");
            $table->string("icon")->nullable()->comment("角色头像/标识");
            $table->string("desc")->nullable()->comment("角色描述");
            $table->tinyInteger("disable")->default(0)->comment("角色禁止分配");

            $table->softDeletes();
            $table->timestamps();

            $table->comment("系统角色表");
        });


        \support\Db::schema()->create('admin_permission',function (Blueprint $table){
            $table->increments('id');

            $table->integer("pid")->unsigned()->default(0)->comment("上级id");
            $table->tinyInteger("type")->default(0)->comment("类型：0菜单，1权限");
            $table->string("name")->nullable()->comment("名称");
            $table->string("path")->nullable()->comment("路径");
            $table->integer("sort")->default(0)->comment("排序值");
            $table->string("description")->default(0)->comment("描述");

            $table->softDeletes();
            $table->timestamps();

            $table->comment("系统权限表");
        });

        \support\Db::schema()->create('admin_menu',function (Blueprint $table){
            $table->increments('id');

            $table->integer("pid")->unsigned()->default(0)->comment("上级id");
            $table->string("name")->nullable()->comment("名称");
            $table->string("icon")->nullable()->comment("图标");
            $table->tinyInteger("type")->default(1)->comment("类型,1目录,2菜单,3按钮");
            $table->tinyInteger("visiable")->default(1)->comment("显示状态,0隐藏，1显示");
            $table->tinyInteger("cacheable")->default(0)->comment("是否缓存,0否，1是");
            $table->string("route_name")->nullable()->comment("前端路由名称");
            $table->string("route_url")->nullable()->comment("前端路由地址");
            $table->string("component_path")->nullable()->comment("前端组件路径");
            $table->string("external_link")->nullable()->comment("外链地址");
            $table->string("permission")->nullable()->comment("权限标识");
            $table->integer("sort")->default(0)->comment("排序值");
            $table->string("description")->default(0)->comment("描述");

            $table->softDeletes();
            $table->timestamps();

            $table->comment("系统菜单表");
        });

        \support\Db::schema()->create('admin_assign',function (Blueprint $table){
            $table->increments('id');

            $table->string("key")->comment("键名，admin-1,role-1");
            $table->string("value")->comment("关联项值");
            $table->tinyInteger("type")->default(1)->comment("类型,1:权限，2菜单");

            $table->timestamps();

            $table->comment("系统权限/菜单分配表");
        });
    }

    public function down(): void
    {
        \support\Db::schema()->dropIfExists('admin_rule');
        \support\Db::schema()->dropIfExists('admin_role');
        \support\Db::schema()->dropIfExists('admin_permission');
        \support\Db::schema()->dropIfExists('admin_menu');
        \support\Db::schema()->dropIfExists('admin_assign');
    }
};